package com.weasing.res.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.weasing.res.dao.IWxUserdetailDao;
import com.weasing.res.dao.base.impl.BaseDaoImpl;
import com.weasing.res.domain.WxUserdetail;

@Repository
public class WxUserdetailDaoImpl extends BaseDaoImpl<WxUserdetail> implements
		IWxUserdetailDao {

	/**
	 * 查询出的数组为 [罪名,案件名称,姓名,总分值,案件Id,嫌疑人Id,评估结果Id]
	 */
	public List<Object[]> findWxUserdetailByCondition(int chargetype,
			String chargename, String totalscore) {
		String hql = "select wud.chargetype,wud.chargename,wul.truename,wes.totalscore,wud.id,wul.id,wes.id "
				+ "from WxUserdetail wud,WxUserlist wul,WxEvalresult wes "
				+ "where wud.userid = wul.id and wud.id = wes.udetailid and wul.id = wes.userid";
		// 罪名
		if (chargetype > 0) {
			hql += " and wud.chargetype = " + chargetype;
		}
		// 案件名称
		if (chargename != null && !"".equals(chargename)) {
			hql += " and wud.chargename like '%" + chargename + "%'";
		}
		// totalscore：1表示羁押，总分小于0；-1表示不羁押，总分大于等于0；0表示全部
		if ("1".equals(totalscore)) {
			hql += " and wes.totalscore < 0";
		} else if ("-1".equals(totalscore)) {
			hql += " and wes.totalscore >= 0";
		}
		List<Object[]> list = (List<Object[]>) this.getHibernateTemplate()
				.find(hql);
		return list;
	}

	@Override
	public List<WxUserdetail> findUserdetailByUserId(Integer userid) {
		String hql = "FROM WxUserdetail"
				+ " u WHERE u.userid = " + userid;
		Session session = this.getSessionFactory().getCurrentSession();
		Query query = session.createQuery(hql);
		return query.list();

	}

}
